package com.lc.dao.impl;

import com.lc.bean.Userinfo;
import com.lc.dao.UserinfoDao;
import com.lc.util.BaseUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: ManolinCoder
 * @time: 2021/8/20
 */
public class UserinfoDaoImpl extends BaseUtil implements UserinfoDao {
    @Override
    public List<Userinfo> selectByUname(String uname) {
        ArrayList<Userinfo> userinfos = new ArrayList<>();
        String sql = "select * from userinfo where uname=?";
        ArrayList<String> unames = new ArrayList<>();
        unames.add(uname);
        ResultSet resultSet = query(sql,unames);
        try {
            while (resultSet.next()){
                Userinfo userinfo = new Userinfo();
                userinfo.setUname(resultSet.getString("uname"));
                userinfo.setPwd(resultSet.getString("pwd"));
                userinfo.setSex(resultSet.getString("sex"));
                userinfo.setTel(resultSet.getString("tel"));
                userinfos.add(userinfo);
            }
        }catch (SQLException e){
            e.printStackTrace();
            return null;
        }finally {
            closeall();
        }
        if (userinfos.size() == 0){
            return null;
        }else {
            return userinfos;
        }
    }
}
